<template>
  <el-dialog
    :title="!dataForm.id ? '新增' : '修改'"
    :close-on-click-modal="false"
    :visible.sync="visible">
    <el-form :model="dataForm" :rules="dataRule" ref="dataForm" @keyup.enter.native="dataFormSubmit()" label-width="80px">
<!--    <el-form-item label="合同编号" prop="protocolid">-->
<!--      <el-input v-model="dataForm.protocolid" placeholder="合同编号"></el-input>-->
<!--    </el-form-item>-->
<!--    <el-form-item label="会员编号" prop="memberId">-->
<!--      <el-input v-model="dataForm.memberId" placeholder="会员编号"></el-input>-->
<!--    </el-form-item>-->
      <el-form-item label="会员编号" prop="memberId">
        <el-select v-model="dataForm.memberId" placeholder="请选择">
          <el-option v-for="(item,i) in memberModel" :label="item.memberNameConcatId" :value="item.memberId"></el-option>
        </el-select>
      </el-form-item>
<!--    <el-form-item label="营销人员编号" prop="userName">-->
<!--      <el-input v-model="dataForm.userName" placeholder="营销人员编号"></el-input>-->
<!--    </el-form-item>-->
      <el-form-item label="营销人员编号" prop="userName">
        <el-select v-model="dataForm.userName" placeholder="请选择">
          <el-option v-for="(item,i) in employeeModel" :label="item.employeeNameConcatId" :value="item.employeeId"></el-option>
        </el-select>
      </el-form-item>
     <el-form-item label="合同签订日期" prop="signDate">
       <el-date-picker
         v-model="dataForm.signDate"
         type="date"
         placeholder="选择日期"
         format="yyyy 年 MM 月 dd 日"
         value-format="yyyy-MM-dd">
       </el-date-picker>
     </el-form-item>
<!--      <div class="block">-->
<!--        <span class="demonstration">默认</span>-->
<!--        <el-date-picker-->
<!--          v-model="value1"-->
<!--          type="date"-->
<!--          placeholder="选择日期">-->
<!--        </el-date-picker>-->
<!--      </div>-->
<!--    <el-form-item label="合同签订日期" prop="signDate">-->
<!--      <el-input v-model="dataForm.signDate" placeholder="合同签订日期"></el-input>-->
<!--    </el-form-item>-->
      <el-form-item label="合同生效开始日期" prop="signdateBegin">
        <el-date-picker
          v-model="dataForm.signdateBegin"
          type="date"
          placeholder="选择日期"
          format="yyyy 年 MM 月 dd 日"
          value-format="yyyy-MM-dd">
        </el-date-picker>
      </el-form-item>
      <el-form-item label="合同生效结束日期" prop="signdateEnd">
        <el-date-picker
          v-model="dataForm.signdateEnd"
          type="date"
          placeholder="选择日期"
          format="yyyy 年 MM 月 dd 日"
          value-format="yyyy-MM-dd">
        </el-date-picker>
      </el-form-item>
<!--    <el-form-item label="合同生效开始日期" prop="signdateBegin">-->
<!--      <el-input v-model="dataForm.signdateBegin" placeholder="合同生效开始日期"></el-input>-->
<!--    </el-form-item>-->
<!--    <el-form-item label="合同生效结束日期" prop="signdateEnd">-->
<!--      <el-input v-model="dataForm.signdateEnd" placeholder="合同生效结束日期"></el-input>-->
<!--    </el-form-item>-->
      <el-form-item label="合同是否生效" prop="vaild">
        <el-select v-model="dataForm.vaild" placeholder="请选择">
          <el-option label="未生效" value="未生效"></el-option>
          <el-option label="生效" value="生效"></el-option>
          <el-option label="失效" value="失效"></el-option>
        </el-select>
      </el-form-item>
<!--    <el-form-item label="合同是否生效 Y-生效 N-失效" prop="vaild">-->
<!--      <el-input v-model="dataForm.vaild" placeholder="合同是否生效 Y-生效 N-失效"></el-input>-->
<!--    </el-form-item>-->
<!--    <el-form-item label="合同审批人" prop="approvalUserName">-->
<!--      <el-input v-model="dataForm.approvalUserName" placeholder="合同审批人"></el-input>-->
<!--    </el-form-item>-->
    </el-form>
    <span slot="footer" class="dialog-footer">
      <el-button @click="visible = false">取消</el-button>
      <el-button type="primary" @click="dataFormSubmit()">确定</el-button>
    </span>
  </el-dialog>
</template>

<script>
  export default {
    created () {
      this.getEmployeeInfo()
      this.getMemberInfo()
    },
    data () {
      return {
        visible: false,
        dataForm: {
          id: 0,
          protocolid: '',
          memberId: '',
          signuserId: '',
          signDate: '',
          signdateBegin: '',
          signdateEnd: '',
          vaild: '',
          approvalUser: '',
          createTime: '',
          updateTime: '',
          userName: '',
          approvalUserName: ''
        },
        dataRule: {
          protocolid: [
            { required: true, message: '合同编号不能为空', trigger: 'blur' }
          ],
          memberId: [
            { required: true, message: '会员编号不能为空', trigger: 'blur' }
          ],
          signuserId: [
            { required: true, message: '营销人员编号不能为空', trigger: 'blur' }
          ],
          signDate: [
            { required: true, message: '合同签订日期不能为空', trigger: 'blur' }
          ],
          signdateBegin: [
            { required: true, message: '合同生效开始日期不能为空', trigger: 'blur' }
          ],
          signdateEnd: [
            { required: true, message: '合同生效结束日期不能为空', trigger: 'blur' }
          ],
          vaild: [
            { required: true, message: '合同是否生效 Y-生效 N-失效不能为空', trigger: 'blur' }
          ],
          approvalUser: [
            /*  { required: true, message: '合同审批人不能为空', trigger: 'blur' } */
          ],
          createTime: [
            { required: true, message: '创建时间不能为空', trigger: 'blur' }
          ],
          updateTime: [
            { required: true, message: '更新时间不能为空', trigger: 'blur' }
          ]
        },
        employeeModel: {
          employeeId: '',
          employeeNameConcatId: ''
        },
        memberModel: {
          memberId: '',
          memberNameConcatId: ''
        }
      }
    },
    methods: {
      init (id) {
        this.dataForm.id = id || 0
        this.visible = true
        this.$nextTick(() => {
          this.$refs['dataForm'].resetFields()
          if (this.dataForm.id) {
            this.$http({
              url: this.$http.adornUrl(`/tb_bs_protocol/bsprotocol/info/${this.dataForm.id}`),
              method: 'get',
              params: this.$http.adornParams()
            }).then(({data}) => {
              if (data && data.code === 0) {
                this.dataForm.protocolid = data.bsProtocol.protocolid
                this.dataForm.memberId = data.bsProtocol.memberId
                this.dataForm.signuserId = data.bsProtocol.signuserId
                this.dataForm.signDate = data.bsProtocol.signDate
                this.dataForm.signdateBegin = data.bsProtocol.signdateBegin
                this.dataForm.signdateEnd = data.bsProtocol.signdateEnd
                this.dataForm.vaild = data.bsProtocol.vaild
                this.dataForm.approvalUser = data.bsProtocol.approvalUser
                this.dataForm.createTime = data.bsProtocol.createTime
                this.dataForm.updateTime = data.bsProtocol.updateTime
                this.dataForm.userName = data.bsProtocol.userName
                this.dataForm.approvalUserName = data.bsProtocol.approvalUserName
              }
            })
          }
        })
      },
      // 表单提交
      dataFormSubmit () {
        this.$refs['dataForm'].validate((valid) => {
          if (valid) {
            this.$http({
              url: this.$http.adornUrl(`/tb_bs_protocol/bsprotocol/${!this.dataForm.id ? 'save' : 'update'}`),
              method: 'post',
              data: this.$http.adornData({
                'id': this.dataForm.id || undefined,
                'protocolid': this.dataForm.protocolid,
                'memberId': this.dataForm.memberId,
                'userName': this.dataForm.userName,
                'signDate': this.dataForm.signDate,
                'signdateBegin': this.dataForm.signdateBegin,
                'signdateEnd': this.dataForm.signdateEnd,
                'vaild': this.dataForm.vaild,
                'approvalUser': this.dataForm.approvalUser,
                'createTime': this.dataForm.createTime,
                'updateTime': this.dataForm.updateTime
              })
            }).then(({data}) => {
              if (data && data.code === 0) {
                this.$message({
                  message: '操作成功',
                  type: 'success',
                  duration: 1500,
                  onClose: () => {
                    this.visible = false
                    this.$emit('refreshDataList')
                  }
                })
              } else {
                this.$message.error(data.msg)
              }
            })
          }
        })
      },
      //获取员工信息下拉
      getEmployeeInfo () {
        this.$http({
          url: this.$http.adornUrl(`/tb_bs_protocol/bsprotocol/queryAllEmployee`),
          method: 'get'
        }).then(({data}) => {
          if (data && data.code === 0) {
            this.employeeModel = data.date
          }
        })
      },
      //获取会员信息下拉
      getMemberInfo () {
        this.$http({
          url: this.$http.adornUrl(`/tb_bs_protocol/bsprotocol/queryAllMember`),
          method: 'get'
        }).then(({data}) => {
          if (data && data.code === 0) {
            this.memberModel = data.date
          }
        })
      }
    }
  }
</script>
